package com.dfcd.commonlib.retrofit.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dfcd.commonlib.R;


/**
 * 加载框
 *
 * @author Administrator
 */
public class DialogUtils {


	private static Dialog instance;

	public DialogUtils() {

	}

	public static synchronized Dialog getInstance(Context context) {
		//if (instance == null) {
			instance = createLoadingDialog(context, null);
		//}
		return instance;
	}


	public static Dialog createLoadingDialog(Context context, String msg) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.dialog_loading, null);// 得到加载view

		LinearLayout layout = v.findViewById(R.id.dialog_loading_view);// 加载布局

		/*ImageView imageView = (ImageView) v.findViewById(R.id.iv_anim_new);
		final AnimationDrawable animDraw = (AnimationDrawable) imageView.getBackground();
		imageView.post(new Runnable() {
			@Override
			public void run() {
				animDraw.start();
			}
		});*/

		TextView tipTextView = v.findViewById(R.id.tipTextView);// 提示文字
		tipTextView.setText(msg);// 设置加载信息

		Dialog loadingDialog = new Dialog(context, R.style.MyDialogStyle);// 创建自定义样式dialog
		loadingDialog.setCancelable(true); // 是否可以按“返回键”消失
		loadingDialog.setCanceledOnTouchOutside(false); // 点击加载框以外的区域
		loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局

		return loadingDialog;
	}


}
